package com.study.service;
import com.study.bean.Stu;
import com.study.dao.StuDao;
import com.study.util.PageTools;
import java.util.List;


public class StuService {
//添加学生
    private  StuDao sd = new StuDao();
    public  boolean addStu(Stu stu){
        StuDao sd = new StuDao();
        int row = sd.addStu(stu);
        return row >0;
    }
    //通过id查询学生信息
    public Stu queryById(String id) {
        return sd.queryById(Integer.parseInt(id));
    }
    //修改学生信息
    public int updateStu(Stu stu) {
        return sd.updateStu(stu);
    }
    //删除学生信息

    public boolean delStu(Integer id) {
        return sd.delStu(id) >0 ;
    }

//获取当前页面学生数据
    public PageTools<Stu> getPageInfo(Stu stu, String currentPage){
        long countNum = sd.getCountNum(stu);
        int initSize = 3;
        int current =1;
        if(null != currentPage && !"".equals(currentPage.trim())){
            current=Integer.parseInt(currentPage);
        }
        PageTools<Stu> pt = new PageTools<>(initSize, current, (int) countNum);
        int start = (current -1) * initSize;
        List<Stu> pageList = sd.getPageList(stu, start, initSize);
        // 交给分页对象
         pt.setPageList(pageList);
         return pt;
    }
}
